package cn.cloud.all.security.web.util.matcher;

import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;

class ELRequestMatcherContext {

    private final HttpServletRequest request;

    ELRequestMatcherContext(HttpServletRequest request) {
        this.request = request;
    }

    public boolean hasIpAddress(String ipAddress) {
        return (new IpAddressMatcher(ipAddress).matches(request));
    }

    public boolean hasHeader(String headerName, String value) {
        String header = request.getHeader(headerName);
        if (!StringUtils.hasText(header)) {
            return false;
        }
        return header.contains(value);
    }
}
